﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpMUD.Framework.Services.Configuration;
using SharpMUD.Framework.Services;
using SharpMUD.Framework.ComponentModel;
using System.Xml.Serialization;

namespace SharpMUD.Application.BootStrap
{
    public sealed partial class MudConfig
        : IConfigurationProvider
    {

        #region IConfigurationProvider Members

        public TServiceConfiguration LoadConfiguration<TService, TServiceConfiguration>()
            where TService : IConfigurableService
            where TServiceConfiguration : IServiceConfiguration<TService>, new()
        {
            return this.Services.First(s => typeof(TService) == s.ServiceTypeType).LoadConfiguration<TServiceConfiguration>();
        }

        public void SaveConfiguration<TService, TServiceConfiguration>(TServiceConfiguration serviceConfiguration)
            where TService : IConfigurableService
            where TServiceConfiguration : IServiceConfiguration<TService>, new()
        {
            this.Services.First(s => typeof(TService) == s.ServiceTypeType).SaveConfiguration<TServiceConfiguration>(serviceConfiguration);
        }

        #endregion

        #region IService Members

        [XmlIgnore]
        public IServicesHost ServicesHost
        {
            get;
            private set;
        }

        public void Initialize(IServicesHost servicesHost)
        {
            this.ServicesHost = servicesHost;
            this.IsInitialized = true;            
        }

        [XmlIgnore]
        public bool IsInitialized
        {
            get;
            private set;
        }

        #endregion
    }
}
